﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class signup : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    /// <summary>
    /// Method to save user data during the sign up process
    /// </summary>
    /// <param name="sender">Form</param>
    /// <param name="e">events</param>
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        //validate the fields on the form
        Validate("signup");

        //If the form field validation is successful
        //read the form data and save it to the DB
        if (this.IsValid)
        {
            Customer cs = new Customer();
            bool userPresent = cs.isExistingCustomer(this.txtEmail.Text);
            if (userPresent != true)
            {
                cs.Email = this.txtEmail.Text;
                cs.Password = this.txtPassword.Text;
                cs.Name = this.txtName.Text;
                cs.Address = this.txtAddress.Text;
                cs.City = this.txtCity.Text;
                cs.State = this.dllState.SelectedValue;
                cs.Zip = this.txtZip.Text;
                bool save = cs.saveCustomerInfo(cs);
                //on successful save redirect user to myAccount page
                if (save)
                {
                    cs.State = this.dllState.SelectedItem.Text;
                    Session["Customer"] = cs;
                    Response.Redirect("myaccount.aspx?signup=true");
                }
            }
            else
            {
                this.lblError.Visible = true;   
            }


        }
    }
}
